function render(b) {
    var a = document.getElementById("main");
    a.innerHTML = tmpl("game", b)
}

function tmpl(d, c) {
    var a = {};
    var b = !/\W/.test(d) ? a[d] = a[d] || tmpl(document.getElementById(d).innerHTML) : new Function("obj", "var p=[],print=function(){p.push.apply(p,arguments);};with(obj){p.push('" + d.replace(/[\r\t\n]/g, " ").split("<%").join("\t").replace(/((^|%>)[^\t]*)'/g, "$1\r").replace(/\t=(.*?)%>/g, "',$1,'").split("\t").join("');").split("%>").join("p.push('").split("\r").join("\\'") + "');}return p.join('');");
    return c ? b(c) : b
}

$(function () {
    var D = $("#home");
    var f = $("#choice");
    var o = $("#choice ul li");
    var u = $("#main > ul li");
    var q = $("#box");
    var start = $("#start");
    var Cover = $("#cover");
    var x = "";
    var k = 0;
    var E = window.appData.list;
    var d = "";
    var c = $("#fail p:first");
    var A = $("#fail p:last");
    var B = $("#success p:first");
    var F = $("#success p:last");
    var j = $(".again");
    var b = "";
    var z = "";
    var r = $(".download");
    var H = [];
    ydk.config({debug: false, jsApiList: ["checkJsApi", "share"]});
    ydk.share({
        type: "",
        title: "分享给你的朋友们~",
        silence: false,
        imgUrl: "https://pic.imgdb.cn/item/615110b42ab3f51d91f96129.png",
        link: "https://secretgleam.gitee.io/angelwang20211028/main.html",
        success: function (I) {
        }
    });
    $(".together").on("click", function (I) {
        ydk.share({
            type: "",
            title: "分享给你的朋友们~",
            silence: false,
            imgUrl: "https://pic.imgdb.cn/item/615110b42ab3f51d91f96129.png",
            link: "https://secretgleam.gitee.io/angelwang20211028/main.html"
        });
        if (!ydk.isYD) {+
            $("#share").removeClass("hidden")
        }
    });
    var n = {Otimer: "", changeText: a, stopChangeText: m, isChanging: false};
    start.on("click", function () {
        $("#lead").removeClass("hidden")
    });
    $(".beginGame").on("click", function () {
        $("#lead").addClass("hidden");
        D.addClass("hidden");
        f.removeClass("hidden");
        o.addClass("hidden");
        q.removeClass("hidden");
        mainFunction()
    });
    o.on("click", function (J) {
        J.stopPropagation();
        var I = $(this).index();
        z = $(this).attr("data-value");
        x = window.appData[z];
        E = x.list;
        k = 0;
        u.each(function () {
            $(this).addClass("hidden")
        });
        u.eq(I).removeClass("hidden");
        f.addClass("hidden");
        mainFunction()
    });
    j.on("click", function () {
        Cover.hide();
        f.removeClass("hidden");
        $("#bad").addClass("hidden");
        $("#true").addClass("hidden");
        $("#main > ul li").addClass("hidden");
        D.addClass("hidden");
        x = "";
        E = window.appData.list;
        k = 0;
        q.removeClass("hidden");
        mainFunction();
        $(".sceneImg").remove()
    });
    Cover.on("click", function () {
        if (k >= E.length && x == "") {
            Cover.hide();
            return
        }
        mainFunction()
    });

    function m() {
        if (n.Otimer) {
            clearInterval(n.Otimer);
            n.Otimer = ""
        }
        n.isChanging = false
    }

    function a(L) {
        var M = L;
        $("#text > p").html("");
        var K = M.split("");
        var J = 0;
        m();

        function I() {
            n.isChanging = true;
            if (J < K.length) {
                $("#text > p").append(K[J].replace("#", "<br>"));
                J = J + 1
            } else {
                n.isChanging = false
            }
        }

        n.Otimer = setInterval(I, 30)
    }

    function choose(N, M) {
        var M = $("#" + M);
        var J = "<div id='chooseBox'></div>";
        var L = "";
        for (var K = 0; K < N.length; K++) {
            var I = N[K].text;
            var O = "<p> " + I + "</p>";
            L = L + O
        }
        M.append(J);
        $("#chooseBox").append(L);
        choiceClick(N);
        Cover.hide()
    }

    function choiceClick(J) {
        var I = $("#chooseBox p");
        I.on("click", function () {
            d = $(this).index();
            if (d !== "") {
                k = 0;
                E = J[d].list;
                mainFunction();
                $("#chooseBox").remove()
            }
        })
    }

    function badend(I) {
        c.html("");
        A.html("");
        c.append(I.title);
        A.append(I.text);
        $("#box").addClass("hidden");
        $("#bad").removeClass("hidden");
        Cover.hide()
    }

    function hiddenchoice(I) {
        B.html("");
        F.html("");
        B.append(I.title);
        F.append(I.text);
        $("#box").addClass("hidden");
        $("#true").removeClass("hidden");
        Cover.hide()
    }

    function expressionImg(K, J) {
        var J = $("#" + J);
        Cover.hide();
        var L = K.url;
        var I = "<div class='stable'></div><img class='expressionImg' src='" + L + "'>";
        J.append(I);
        normal(K.text);
        $(".stable").on("click", function () {
            $(".expressionImg").remove();
            $(".stable").remove();
            mainFunction()
        })
    }

    function showhidden(I) {
        o.removeClass("hidden");
        normal(I)
    }

    function mainFunction() {
        Cover.show();
        var I = z;
        b = E[k];
        var J = b.type;
        switch (J) {
            case -1:
                badend(b);
                k = 0;
                break;
            case 0:
                normal(b.text);
                k++;
                break;
            case 1:
                homeImage(b, b.text);
                k++;
                break;
            case 2:
                normal(b.text);
                choose(b.answers, I);
                break;
            case 4:
                expressionImg(b, I);
                k++;
                break;
            case 5:
                sceneImg(b, I);
                k++;
                break;
            case 6:
                hiddenchoice(b);
                break;
            case 7:
                showhidden(b.text);
                k++;
                break;
            default:
                break
        }
    }

    function homeImage(J, I) {
        var I = $("#homescreen");
        Cover.hide();
        var L = J.url;
        I.attr("src", L);
    }
    function sceneImg(J, I) {
        var I = $("#" + I);
        Cover.hide();
        var L = J.url;
        var K = "<img class='sceneImg setImg' src='" + L + "'>";
        I.append(K);
        $(".sceneImg").on("click", function () {
            mainFunction();
            $(".sceneImg").unbind()
        })
    }

    function normal(I) {
        n.changeText(I)
    }
});
